<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;

class SystemConfigTable extends Model
{
    use HasFactory;
    use PimpableTrait;

    public $searchable = [
        'name',
        'english_name',
        'type',
    ];

    public $fillable = [
        'pid',
        'name',
        'english_name',
        'type',
    ];

    protected $defaultSortCriteria = ['sort,desc'];

    /**
     * 附件下的子类查询
     */
    public function childrens()
    {
        return $this->hasMany(SystemConfigTable::class,'pid','id');
    }

    /**
     * 附件分类下的所有附件
     */
    public function systemConfig()
    {
        return $this->hasMany(SystemConfig::class, 'config_table_id','id');
    }

    /**
     * 附件分类所属管理员添加
     */
    public function systemAdmin()
    {
        return $this->belongsTo(SystemAdmin::class, 'system_admin_id','id');
    }

}
